home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 18 / CU Amiga Magazine's Super CD-ROM 18 (1997)(EMAP Images)(GB)[!][issue 1998-01].iso / CUCD / Programming / AmigaE / Src / OOmodules / sort.e < prev   
Encoding:
Text File  |  1995-10-26  |  7.8 KB  |  359 lines

  1. -> sortobj.e: An abstract data manipulation class for Amiga E
  2. -> It's written by Trey Van Riper of the Cheese Olfactory Workshop.
  3. OPT MODULE
  4. OPT EXPORT
  5.  
  6. MODULE 'oomodules/object'
  7.  
  8. -> This is a totally abstract object to handle comparable objects.
  9.  
  10. OBJECT sort OF object
  11. /****** sort/--sort-- ******************************************
  12.  
  13.     NAME
  14.         sort of object
  15.  
  16.     PURPOSE
  17.         The sort object basically handles sortable objects.  Objects that
  18.         can be sorted in any way (alphanumerically, numerically, category,
  19.         etc) should be derived from Sort. All one should really have to do
  20.         to make their Sort object work is to create a method 'cmp()', per
  21.         below.
  22.  
  23.     ATTRIBUTES
  24.         None at all.
  25.  
  26.     NOTES
  27.         The following functions are comparitive functions for deciding what
  28.         is greater than, less than, or equal to what.  You'll note that to
  29.         make all of these work, one only needs to define 'cmp()' in one's
  30.         own derived object... the rest of these will auto-magically work!
  31.  
  32. ******************************************************************************
  33.  
  34. History
  35.  
  36.  
  37. */
  38. ENDOBJECT
  39.  
  40.  
  41. -> lt() means 'less than'.
  42.  
  43. PROC lt(item:PTR TO sort) OF sort IS IF self.cmp(item)<0 THEN TRUE ELSE FALSE
  44. /****** sort/lt ******************************************
  45.  
  46.     NAME 
  47.         lt() -- Test if an item is lower than itself.
  48.  
  49.     SYNOPSIS
  50.         self.lt(item:PTR TO sort)
  51.  
  52.     FUNCTION
  53.         It tests if the item provided is in some way lower than itself.
  54.  
  55.     INPUTS
  56.         item:PTR TO sort -- Item to compare to.
  57.  
  58.     RESULT
  59.         TRUE if item is lower than itself, FALSE otherwise.
  60.  
  61.     SEE ALSO
  62.         cmp()
  63. ******************************************************************************
  64.  
  65. History
  66.  
  67.  
  68. */
  69.  
  70. -> gt() means 'greater than'.
  71.  
  72. PROC gt(item:PTR TO sort) OF sort IS IF self.cmp(item)>0 THEN TRUE ELSE FALSE
  73. /****** sort/gt ******************************************
  74.  
  75.     NAME 
  76.         lt() -- Test if an item is greater than itself.
  77.  
  78.     SYNOPSIS
  79.         self.gt(item:PTR TO sort)
  80.  
  81.     FUNCTION
  82.         It tests if the item provided is in some way greater than itself.
  83.  
  84.     INPUTS
  85.         item:PTR TO sort -- Item to compare to.
  86.  
  87.     RESULT
  88.         TRUE if item is greater than itself, FALSE otherwise.
  89.  
  90.     SEE ALSO
  91.         cmp()
  92. ******************************************************************************
  93.  
  94. History
  95.  
  96.  
  97. */
  98.  
  99. -> et() means 'equal to'.
  100.  
  101. PROC et(item:PTR TO sort) OF sort IS IF self.cmp(item)=0 THEN TRUE ELSE FALSE
  102. /****** sort/et ******************************************
  103.  
  104.     NAME 
  105.         lt() -- Test if an item is equal to itself.
  106.  
  107.     SYNOPSIS
  108.         self.et(item:PTR TO sort)
  109.  
  110.     FUNCTION
  111.         It tests if the item provided is the same as itself.
  112.  
  113.     INPUTS
  114.         item:PTR TO sort -- Item to compare to.
  115.  
  116.     RESULT
  117.         TRUE if item is the same as itself, FALSE otherwise.
  118.  
  119.     SEE ALSO
  120.         cmp()
  121. ******************************************************************************
  122.  
  123. History
  124.  
  125.  
  126. */
  127.  
  128. -> le() means 'Less than/Equal to'.
  129.  
  130. PROC le(item:PTR TO sort) OF sort IS IF self.lt(item) OR self.et(item) THEN TRUE ELSE FALSE
  131. /****** sort/le ******************************************
  132.  
  133.     NAME 
  134.         le() -- Test if an item is lower than or equal to itself.
  135.  
  136.     SYNOPSIS
  137.         self.le(item:PTR TO sort)
  138.  
  139.     FUNCTION
  140.         It tests if the item provided is in some way lower than or equal
  141.         to itself.
  142.  
  143.     INPUTS
  144.         item:PTR TO sort -- Item to compare to.
  145.  
  146.     RESULT
  147.         TRUE if item is lower than or equal to itself, FALSE otherwise.
  148.  
  149.     SEE ALSO
  150.         cmp()
  151. ******************************************************************************
  152.  
  153. History
  154.  
  155.  
  156. */
  157.  
  158. -> ge() means 'Greater than/Equal to'.
  159.  
  160. PROC ge(item:PTR TO sort) OF sort IS IF self.gt(item) OR self.et(item) THEN TRUE ELSE FALSE
  161. /****** sort/ge ******************************************
  162.  
  163.     NAME 
  164.         ge() -- Test if an item is greater than or equal to itself.
  165.  
  166.     SYNOPSIS
  167.         self.ge(item:PTR TO sort)
  168.  
  169.     FUNCTION
  170.         It tests if the item provided is in some way greater than or equal
  171.         to itself.
  172.  
  173.     INPUTS
  174.         item:PTR TO sort -- Item to compare to.
  175.  
  176.     RESULT
  177.         TRUE if item is greater than or equal to itself, FALSE otherwise.
  178.  
  179.     SEE ALSO
  180.         cmp()
  181. ******************************************************************************
  182.  
  183. History
  184.  
  185.  
  186. */
  187.  
  188. -> ne() means 'Not Equal to'.
  189.  
  190. PROC ne(item:PTR TO sort) OF sort IS IF self.et(item) THEN FALSE ELSE TRUE
  191. /****** sort/ne ******************************************
  192.  
  193.     NAME 
  194.         ne() -- Test if an item is not equeal to itself.
  195.  
  196.     SYNOPSIS
  197.         self.ne(item:PTR TO sort)
  198.  
  199.     FUNCTION
  200.         It tests if the item provided is not equal to itself.
  201.  
  202.     INPUTS
  203.         item:PTR TO sort -- Item to compare to.
  204.  
  205.     RESULT
  206.         TRUE if item is not equal to itself, FALSE otherwise.
  207.  
  208.     SEE ALSO
  209.         cmp()
  210. ******************************************************************************
  211.  
  212. History
  213.  
  214.  
  215. */
  216.  
  217. -> cmp() means 'Compare', and will return 1, 0, or -1 depending upon whether
  218. -> the internal item is Less than, Equal to, or Greater than the incoming item.
  219. -> All the other comparative functions above depend upon this one, so don't
  220. -> mess it up <grin>.
  221.  
  222. PROC cmp(item:PTR TO sort) OF sort IS self.derivedClassResponse()
  223. /****** sort/cmp ******************************************
  224.  
  225.     NAME 
  226.         cmp() -- Compare an item to itself.
  227.  
  228.     SYNOPSIS
  229.         self.cmp(item:PTR TO sort)
  230.  
  231.     FUNCTION
  232.         cmp() means 'Compare', and will return 1, 0, or -1 depending upon
  233.         whether the internal item is Less than, Equal to, or Greater than
  234.         the incoming item. All the other comparative functions above depend
  235.         upon this one, so don't mess it up <grin>.
  236.  
  237.     INPUTS
  238.         item:PTR TO sort -- Item to compare to.
  239.  
  240.     RESULT
  241.         -1 -- item is lower than itself
  242.          0 -- item is equal to itself
  243.         +1 -- item is greater than itself
  244.  
  245. ******************************************************************************
  246.  
  247. History
  248.  
  249.  
  250. */
  251.  
  252. -> set() merely sets a value.
  253.  
  254. PROC set(in) OF sort IS self.derivedClassResponse()
  255. /****** sort/set ******************************************
  256.  
  257.     NAME 
  258.         set() -- Set value of instance.
  259.  
  260.     SYNOPSIS
  261.         sort.set(objectSpecific)
  262.  
  263.     FUNCTION
  264.         Set the value of the instance.
  265.  
  266.     INPUTS
  267.         objectSpecific -- use it as you want.
  268.  
  269.     NOTES
  270.         Does nothing.
  271.  
  272. ******************************************************************************
  273.  
  274. History
  275.  
  276.  
  277. */
  278.  
  279. -> write() creates a string of an item to print.
  280.  
  281. PROC write() OF sort IS self.derivedClassResponse()
  282. /****** sort/write ******************************************
  283.  
  284.     NAME 
  285.         write() -- Create printable string from object.
  286.  
  287.     SYNOPSIS
  288.         sort.write()
  289.  
  290.     FUNCTION
  291.         Creates a string of an item to print.
  292.  
  293.     NOTES
  294.         Does nothing.
  295.  
  296. ******************************************************************************
  297.  
  298. History
  299.  
  300.  
  301. */
  302.  
  303. -> get() returns the item itself (if appropriate).
  304.  
  305. PROC get() OF sort IS self.derivedClassResponse()
  306. /****** sort/get ******************************************
  307.  
  308.     NAME 
  309.         get() -- Get instance value.
  310.  
  311.     SYNOPSIS
  312.         sort.get()
  313.  
  314.     FUNCTION
  315.         Gets the instance's value.
  316.  
  317.     RESULT
  318.         Hopefully the value.
  319.  
  320.     NOTES
  321.         Does nothing for now.
  322.  
  323.     SEE ALSO
  324.         set()
  325. ******************************************************************************
  326.  
  327. History
  328.  
  329.  
  330. */
  331.  
  332. -> name() returns a unique name for the type of object.
  333.  
  334. PROC name() OF sort IS 'Sort'
  335. /****** sort/name ******************************************
  336.  
  337.     NAME 
  338.         name() -- Get name of object.
  339.  
  340.     SYNOPSIS
  341.         sort.name()
  342.  
  343.     FUNCTION
  344.         Gets the name of the object.
  345.  
  346.     RESULT
  347.         Pointer to string containing the name.
  348.  
  349. ******************************************************************************
  350.  
  351. History
  352.  
  353.  
  354. */
  355. /*EE folds
  356. 1
  357. 10 29 
  358. EE folds*/
  359.